package com.order.manager.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.order.manager.Model.CollectInfo;
import com.order.manager.Model.ShopInfo;
import com.order.manager.mapper.ShopInfoMapper;
import com.order.manager.service.ShopInfoService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 24862
 * @description 针对表【shop_info】的数据库操作Service实现
 * @createDate 2024-04-08 15:32:34
 */
@Service
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {

    @Resource
    ShopInfoMapper shopInfoMapper;


    @Resource
    CollectInfoServiceImpl collectInfoService;

    @Resource
    UserInfoServiceImpl userInfoService;

    @Override
    public PageInfo<ShopInfo> queryByShopName(int page, int item, String shopName) {
        PageMethod.startPage(page, item);
        List<ShopInfo> shopInfos = shopInfoMapper.selectList(new QueryWrapper<ShopInfo>().like("shop_name", shopName).eq("business_state", 1).eq("shop_state", 3));
        shopInfos.forEach(el -> el.setShopMasterId(String.valueOf(collectInfoService.count(new QueryWrapper<CollectInfo>().eq("collect_shop_id", el.getShopId())))));
        return new PageInfo<>(shopInfos);
    }

    @Override
    public PageInfo<ShopInfo> queryByShopAndUserCollect(int page, int item, String shopName, String uuid) {
        PageMethod.startPage(page, item);
        List<ShopInfo> shopInfos = shopInfoMapper.queryByUserIdShopName(shopName, uuid);
        shopInfos.forEach(el -> el.setShopMasterId(String.valueOf(collectInfoService.count(new QueryWrapper<CollectInfo>().eq("collect_shop_id", el.getShopId()).eq("shop_state", 3)))));
        return new PageInfo<>(shopInfos);
    }

    @Override
    public PageInfo<ShopInfo> queryBySchool(int page, int item) {
        PageMethod.startPage(page, item);
        List<ShopInfo> shopInfos = shopInfoMapper.selectList(null);
        shopInfos.forEach(el -> el.setShopMasterId(JSON.toJSONString(userInfoService.getById(el.getShopMasterId()))));
        return new PageInfo<>(shopInfos);
    }


}




